/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package czStvDpds.graphics3D.gui;

import org.newdawn.slick.UnicodeFont;

/**
 *
 * @author Ondra
 */
public class TextPiece {

    public static final int MAX_LENGTH = 7;
    private String text;
    private int x;
    private int y;

    private TextPiece(String text, int x, int y) {
        this.text = text;
        this.x = x;
        this.y = y;
    }

    public String getText() {
        return text;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public static TextPiece[] cut(String wholeText, int x, int y, UnicodeFont font) {
        int length = wholeText.length();
        TextPiece[] result = new TextPiece[(length / TextPiece.MAX_LENGTH) + 1];

        int index = 0;
        int currentX = x;
        for (int i = 0; i < result.length; i++) {
            String substring = wholeText.substring(index, (index + TextPiece.MAX_LENGTH > length) ? length : (index + TextPiece.MAX_LENGTH));
            result[i] = new TextPiece(substring, currentX, y);
            currentX += font.getWidth(substring);
            index += TextPiece.MAX_LENGTH;
        }

        return result;
    }
}
